package newcrunch.tests;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import newcrunch.typography.JavaAnalyzer;
import newcrunch.typography.TypoResults;

/**
 * @author WL
 */

interface A{}
interface B{}
public class TypoTest <T extends A & B> extends Object
{
    ;;;;
    static {
        
    }
    @Foo
    (
            apple = 1
    )
            
    void method(String foo)
    {
        int i = ~(1 + 2 * 3 - 4 / 5 % 6 & 7 ^ 8 | 9);
        int number = i++;
        String something = "\u1234";
    }
    
    private static String readFile(File file) throws IOException 
    {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line  = null;
        StringBuilder stringBuilder = new StringBuilder();
        
        String ls = System.getProperty("line.separator");
        
        while ((line = reader.readLine()) != null) 
        {
            stringBuilder.append(line);
            stringBuilder.append(ls);
        }
        
        return stringBuilder.toString();
 }
    
    
    public static void checkSource(File dir, JavaAnalyzer analyzer)
    {
        File[] inner = dir.listFiles();
        
        for (File file : inner)
        {
            if (file.isDirectory())
                checkSource(file, analyzer);
            else if (file.getName().endsWith(".java"))
            {
                try {
                    TypoResults result = analyzer.analyzeTokens(readFile(file));
                } catch (Exception e) {
                    System.out.println(file.getAbsolutePath() + " : " + e.getClass().getName());
                }
            }
        }
    }
    
    public static void main(String[] args)
    {
        //String root = "D:/My Documents/Java/NewCrunch2/src/main/java/";
        String root = "D:/My Documents/Java/";
        File dir = new File(root);
        
        JavaAnalyzer analyzer = JavaAnalyzer.getInstance();
        
        if (dir.isDirectory())
            checkSource(dir, analyzer);
    }
}

@interface Foo
{
    int apple() default 0;
    float pear() default 1;
    String dual() default "dual";
}

strictfp enum EnumNum implements java.util.Comparator<Integer>, Small<java.util.List<Integer>>
{
    APPLE() { }, ORANGE, PEAR;
    public int compare(Integer o1, Integer o2) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
